package main

import (
	"context"
	"fmt"
	"time"
)

func main() {
	var arr = []int{7, 2, 31, 90, 45, 88, 12, 34, 22, 98, 67, 38, 29, 24, 75, 18}
	t := time.NewTimer(5 * time.Second)
	c := make(chan bool)
	num := 5
	ctx, cancel := context.WithCancel(context.Background())
	l := len(arr)

	for i := 0; i < l; i += num {
		if (i + num) < l {
			go test123(arr[i:i+num], ctx, c, 341)
		} else {
			go test123(arr[i:], ctx, c, 34)
		}
	}

	select {
	case <-t.C:
		fmt.Println("时间到了")
		cancel()
	case <-c:
		fmt.Println("找到了")
		cancel()
	}
}

func test123(arr []int, ctx context.Context, c chan bool, find int) bool {

	for _, v := range arr {
		select {
		case <-ctx.Done():
		default:
		}

		if v == find {
			c <- true
			return true
		}
	}
	return false
}
